package com.vhdadw.contoller;


import com.vhdadw.contoller.request.ShortLinkAddRequest;
import com.vhdadw.contoller.request.ShortLinkDelRequest;
import com.vhdadw.contoller.request.ShortLinkPageRequest;
import com.vhdadw.contoller.request.ShortLinkUpdateRequest;
import com.vhdadw.service.ShortLinkService;
import com.vhdadw.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/link/v1")
public class ShortLinkController {

    @Autowired
    private ShortLinkService shortLinkService;

    /**
     * 新增短链
     * @param request
     * @return
     */
    @PostMapping("/add")
    public JsonData createShortLink(@RequestBody ShortLinkAddRequest request){

        JsonData jsonData = shortLinkService.createShortLink(request);

        return jsonData;
    };


    @RequestMapping("/page")
    public JsonData pageByGroupId(@RequestBody ShortLinkPageRequest request){

        Map<String,Object> result = shortLinkService.pageByGroupId(request);

        return JsonData.buildSuccess(result);

    }

    /**
     * 删除短链
     * @param request
     * @return
     */
    @PostMapping("/del")
    public JsonData del(@RequestBody ShortLinkDelRequest request){

        JsonData jsonData = shortLinkService.del(request);

        return jsonData;
    };

    /**
     * 更新短链
     * @param request
     * @return
     */
    @PostMapping("/update")
    public JsonData update(@RequestBody ShortLinkUpdateRequest request){

        JsonData jsonData = shortLinkService.update(request);

        return jsonData;
    };
}
